home *** CD-ROM | disk | FTP | other *** search
- /* -----------------------------------------------------------------------------
-
- GEDApp 1.1 - GoldED AppIcon handler, ©1996 Dietmar Eilert
-
- DICE:
-
- dcc app.c appIconA.a -// -proto -mRR -mi -pr -2.0 -o ram:AppIcon
-
- CONTENTS
-
- C source code of GEDApp.
-
- PURPOSE
-
- GEDApp is a simple AppIcon handler for the editor GoldED. It will put an
- Application icon on the workbench screen. Icons of text files may be dragged
- and dropped over this icon to make GoldED load them into a new window.
- Doubleclick at the AppIcon to make it disappear.
-
- INSTALLATION
-
- There is nothing to install - simply doubleclick GEDApp's icon to run it. Or
- copy this utility to your WBStartup drawer if you want to have it available
- every time you boot your Amiga. GEDApp uses the default AppIcon of GoldED
- itself, so GoldED should already be installed.
-
- HOW TO SET THE DEFAULT ICON POSITION ...
-
- Open the 'golded:icons' drawer. Move the 'AppIcon' icon from within that
- directory to your preferred position, than snapshot it (workbench/icon menu).
- Finally move the icon back to its drawer. GEDApp will read the new position
- the next time it is evoked.
-
- ------------------------------------------------------------------------------
- */
-
- /// "includes"
-
- #include <amiga20/exec/exec.h>
- #include <string.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <stdarg.h>
- #include <amiga20/intuition/intuition.h>
- #include <amiga20/dos/dos.h>
- #include <amiga20/dos/dosextens.h>
- #include <amiga20/dos/rdargs.h>
- #include <amiga20/dos/dostags.h>
- #include <amiga20/workbench/startup.h>
- #include <amiga20/workbench/workbench.h>
- #include <amiga20/rexx/errors.h>
- #include <amiga20/rexx/rxslib.h>
-
- #include <amiga20/clib/alib_protos.h>
- #include <amiga20/clib/dos_protos.h>
- #include <amiga20/clib/exec_protos.h>
- #include <amiga20/clib/icon_protos.h>
- #include <amiga20/clib/intuition_protos.h>
- #include <amiga20/clib/utility_protos.h>
- #include <amiga20/clib/rexxsyslib_protos.h>
- #include <amiga20/clib/wb_protos.h>
-
- #ifdef PRAGMAS
-
- #include "Pragmas/exec.h"
- #include "Pragmas/disk.h"
- #include "Pragmas/diskfont.h"
- #include "Pragmas/dynamic.h"
- #include "Pragmas/gadtools.h"
- #include "Pragmas/keymap.h"
- #include "Pragmas/graphics.h"
- #include "Pragmas/icon.h"
- #include "Pragmas/input.h"
- #include "Pragmas/intuition.h"
- #include "Pragmas/layers.h"
- #include "Pragmas/locale.h"
- #include "Pragmas/misc.h"
- #include "Pragmas/timer.h"
- #include "Pragmas/wb.h"
- #include "Pragmas/xpkmaster.h"
- #include "Pragmas/amigaguide.h"
- #include "Pragmas/reqtools.h"
-
- #endif
-
- #define Prototype extern
- #define MAX_LEN 150
-
- ///
- /// "prototypes"
-
- Prototype void main(ULONG, char **);
- Prototype int wbmain(struct WBStartup *);
- Prototype void MainLoop(void);
- Prototype UBYTE *MakeFileName (UBYTE *, UBYTE *);
- Prototype UBYTE *CompletePath(UBYTE *);
- Prototype UBYTE *StartGED(void);
- Prototype struct RexxMsg *SendRexxCommand(UBYTE *, UBYTE *, struct MsgPort *);
- Prototype void FreeRexxCommand (struct RexxMsg *);
- Prototype ULONG WaitForAnswer(struct MsgPort *);
- Prototype UBYTE *LookForGED(void);
- Prototype void ReadWBCmd(ULONG, struct WBArg *);
-
- extern struct Library *IconBase;
- extern struct Library *DOSBase;
- extern struct Library *SysBase;
- extern struct Library *IntuitionBase;
- extern struct Library *WorkbenchBase;
-
- // globals
-
- UBYTE Version[] = "$VER: AppIcon 3.0 (" __COMMODORE_DATE__ ")";
-
- ///
- /// "entry points"
-
- void
- main(argc, argv)
-
- ULONG argc;
- char *argv[];
- {
- MainLoop();
- }
-
- int
- wbmain(struct WBStartup *wbs)
- {
- MainLoop();
- }
-
-
- ///
- /// "main loop"
-
- /* --------------------------------- MainLoop ----------------------------------
-
- Open AppIcon, handle incoming messages
-
- */
-
- void
- MainLoop()
- {
- struct DiskObject *appDiskObject;
-
- appDiskObject = GetDiskObject("golded:icons/appicon");
-
- if (appDiskObject == NULL)
-
- appDiskObject = GetDefDiskObject(WBTOOL);
-
- if (appDiskObject) {
-
- struct MsgPort *msgPort;
- struct AppMessage *amsg;
- struct AppIcon *appIcon;
-
- if (msgPort = CreateMsgPort()) {
-
- if (appIcon = AddAppIconA(0, NULL, "GoldED", msgPort, NULL, appDiskObject, TAG_END)) {
-
- BOOL terminated = FALSE;
-
- while (terminated == FALSE) {
-
- while (amsg = (struct AppMessage *)GetMsg(msgPort)) {
-
- if (amsg->am_NumArgs)
- ReadWBCmd(amsg->am_NumArgs, amsg->am_ArgList);
- else
- terminated = TRUE;
-
- ReplyMsg((struct Message *)amsg);
- }
-
- WaitPort(msgPort);
- }
- }
- else
- puts("Couldn't allocate AppIcon. Workbench closed ?!");
-
- RemoveAppIcon(appIcon);
-
- DeleteMsgPort(msgPort);
- }
- else
- puts("Couldn't create message port ?!");
-
- FreeDiskObject(appDiskObject);
- }
- else
- puts("Impossible d'allouer DiskObject ?!");
-
- exit(0);
- }
-
-
- ///
- /// "misc"
-
- /* ------------------------------- MakeFileName --------------------------------
-
- Build fully qualified path from file/path names; return pointer to static copy.
-
- */
-
- UBYTE *
- MakeFileName(path, file)
-
- UBYTE *path, *file;
- {
- static UBYTE buffer[MAX_LEN + 1];
-
- strcpy(buffer, "\42");
-
- strcat(buffer, path);
-
- CompletePath(buffer);
-
- strcat(buffer, file);
-
- strcat(buffer, "\42");
-
- return(buffer);
- }
-
- /* ------------------------------ CompletePath -----------------------------------
-
- Add '/' to path if missing so far
-
- */
-
- UBYTE *
- CompletePath(path)
-
- UBYTE *path;
- {
- UWORD len;
-
- if (len = strlen(path))
-
- if ((path[len - 1] != ':') && (path[len - 1] != '/'))
-
- strcat(path, "/");
-
- return(path);
- }
-
- /* ---------------------------------- ReadWBCmd --------------------------------
-
- Parse AppIcon message
-
- */
-
- void
- ReadWBCmd(numArgs, argList)
-
- ULONG numArgs;
- struct WBArg *argList;
- {
- UBYTE *host;
-
- Forbid();
-
- host = LookForGED();
-
- Permit();
-
- if (host == NULL)
-
- host = StartGED();
-
- if (host) {
-
- struct MsgPort *replyPort;
-
- if (replyPort = CreateMsgPort()) {
-
- if (SendRexxCommand(host, "LOCK CURRENT RELEASE=4", replyPort)) {
-
- if (WaitForAnswer(replyPort) == RC_OK) {
-
- UBYTE path[MAX_LEN + 1];
-
- UWORD count;
- UBYTE *command;
-
- for (count = 0; numArgs--; count++) {
-
- NameFromLock(argList[count].wa_Lock, path, MAX_LEN);
-
- command = MakeFileName(path, argList[count].wa_Name);
-
- strins(command, "OPEN SMART QUIET ");
-
- if (SendRexxCommand(host, command, replyPort))
-
- WaitForAnswer(replyPort);
- }
- }
-
- if (SendRexxCommand(host, "UNLOCK", replyPort))
-
- WaitForAnswer(replyPort);
- }
-
- DeleteMsgPort(replyPort);
- }
- }
- }
-
-
- /* ----------------------------------- LookForGED ----------------------------
-
- Look for running GoldED task
-
- */
-
- UBYTE *
- LookForGED()
- {
- static UBYTE host[] = "GOLDED.1";
-
- UWORD try;
-
- for (try = '1'; try <= '9'; try++) {
-
- host[7] = try;
-
- if (FindPort(host))
-
- return(host);
- }
-
- return(NULL);
- }
-
-
- /* ------------------------------------- StartGED -----------------------------
-
- Launch a new GoldED task. Return pointer to host name (or NULL).
-
- */
-
- UBYTE *
- StartGED()
- {
- struct MsgPort *port = NULL;
-
- if (SystemTags("GoldED:GoldED", SYS_Asynch, TRUE, SYS_Input, NULL, SYS_Output, NULL, TAG_DONE) == 0) {
-
- UWORD try;
-
- for (try = 50; try; (port == NULL) && try--, Delay(10)) {
-
- Forbid();
-
- port = FindPort("GOLDED.1");
-
- Permit();
- }
- }
-
- return((port) ? "GOLDED.1" : NULL);
- }
-
- ///
- /// "ARexx"
-
- /* -------------------------------------- WaitForAnswer -----------------------
-
- Wait for answer on previously sent message. Free message afterwards. Primary
- return code is returned.
-
- */
-
- ULONG
- WaitForAnswer(port)
-
- struct MsgPort *port;
- {
- struct RexxMsg *rexxMsg;
- ULONG result;
-
- do {
-
- WaitPort(port);
-
- if (rexxMsg = (struct RexxMsg *)GetMsg(port))
- result = rexxMsg->rm_Result1;
-
- } while (!rexxMsg);
-
- FreeRexxCommand(rexxMsg);
-
- return(result);
- }
-
-
- /* ------------------------------------- FreeRexxCommand ----------------------
-
- Free ARexx message
-
- */
-
- void
- FreeRexxCommand(rexxmessage)
-
- struct RexxMsg *rexxmessage;
- {
- if (rexxmessage->rm_Result1 == RC_OK)
-
- if (rexxmessage->rm_Result2)
-
- DeleteArgstring((char *)rexxmessage->rm_Result2);
-
- DeleteArgstring((char *)ARG0(rexxmessage));
-
- DeleteRexxMsg(rexxmessage);
- }
-
-
- /* ---------------------------------- SendRexxCommand -------------------------
-
- Send ARexx message
-
- */
-
- struct RexxMsg *
- SendRexxCommand(port, cmd, replyPort)
-
- struct MsgPort *replyPort;
- UBYTE *cmd, *port;
- {
- struct MsgPort *rexxport;
- struct RexxMsg *rexx_command_message = NULL;
-
- Forbid();
-
- if (rexxport = FindPort(port)) {
-
- if (rexx_command_message = CreateRexxMsg(replyPort, NULL, NULL)) {
-
- if (rexx_command_message->rm_Args[0] = CreateArgstring(cmd, strlen(cmd))) {
-
- rexx_command_message->rm_Action = RXCOMM | RXFF_RESULT;
-
- PutMsg(rexxport, &rexx_command_message->rm_Node);
- }
- }
- }
-
- Permit();
-
- return(rexx_command_message);
- }
-
- ///
-